from django.db import models

# Create your models here.
# 书籍表
class BookModel(models.Model):
    CHOICE_STATUS = {
        ('1','可借'),
        ('2','借出'),
    }
    title = models.CharField(max_length=255, verbose_name='书籍名称')
    author = models.CharField(max_length=255, verbose_name='作者')
    number = models.IntegerField(verbose_name='数量')
    status = models.CharField(max_length=10, choices=CHOICE_STATUS, verbose_name='书籍状态')

    class Meta:
        db_table = 'books'
        verbose_name = '书籍'
        verbose_name_plural = verbose_name


    def __str__(self):
        return self.title

class BookRecordModel(models.Model):
    book = models.ForeignKey(BookModel, on_delete=models.CASCADE, verbose_name='书籍')
    reader = models.CharField(max_length=255, verbose_name='借阅人')
    is_return = models.BooleanField(default=False, verbose_name='是否归还')
    number = models.IntegerField(verbose_name='借阅数量', default=0)
    borrow_date = models.DateTimeField(auto_now_add=True, verbose_name='借阅时间')
    return_date = models.DateTimeField(null=True, blank=True, verbose_name='归还时间')

    class Meta:
        db_table = 'book_record'
        verbose_name = '借阅记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.book.title



